package cn.edu.jxyy.p5;

import java.lang.reflect.Proxy;

public class TestDynamicProxy {
    public static void main(String[] args) {
        MyInvocationHandler myInvocationHandler =
                new MyInvocationHandler(new TomFlower());
        IFlower flower = (IFlower) Proxy.newProxyInstance(
                IFlower.class.getClassLoader(),
                new Class[] { IFlower.class },
                myInvocationHandler);
        flower.sendFlower();
        flower.sendBook();

        MyInvocationHandler jamesInvocationHandler =
                new MyInvocationHandler(new JamesFlower());
        IFlower jamesflower = (IFlower) Proxy.newProxyInstance(
                IFlower.class.getClassLoader(),
                new Class[] { IFlower.class },
                jamesInvocationHandler);
        jamesflower.sendFlower();
        jamesflower.sendBook();
    }
}

